﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using WordpressRestApi;

namespace ApiClientTest
{
    /// <summary>Base class for test classes using the client.</summary>
    public abstract class ClientTestBase
    {
        /// <summary>Returns a working client.</summary>
        /// <returns></returns>
        protected WordpressClient CreateClient()
        {
            var token = ConfigurationManager.AppSettings["accessToken"];
            var blogID = ConfigurationManager.AppSettings["blogID"];
            var blogUrl = ConfigurationManager.AppSettings["blogUrl"];

            if (string.IsNullOrWhiteSpace(token)
                || string.IsNullOrWhiteSpace(blogID)
                || string.IsNullOrWhiteSpace(blogUrl))
            {
                throw new ApplicationException("Make sure to create a file named local.override.config and place it in the bin/debug folder (see app.config)");
            }
            else
            {
                return new WordpressClient(new TokenInfo
                {   //  Temporary token, will require to be updated
                    AccessToken = token,
                    //  Points to a specific blog used for tests
                    BlogID = blogID,
                    BlogUrl = blogUrl
                });
            }
        }
    }
}